// pages/my/news/news.js
const con = require("../../../utils/data.js");
const WXAPI = require('../../../wxapi/main')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    active: 0,
    barbershop:[],
    shopId:0,
    distance:600,
    curPage: 1,
    pageSize: 20,

  },
  // 页面跳转
  go(){
    // wx.makePhoneCall({
    //   phoneNumber: '1340000' //仅为示例，并非真实的电话号码
    // })
    wx.showToast({
      title: '尚未开通该功能'
  })
  },
  gohair() {
    wx.navigateTo({
      url: './hair/hair',
    })
  },
  gomassage() {
    wx.navigateTo({
      url: '../massage/massage',
    })
  },
  
  goDetails(e){
      console.log("e---"+JSON.stringify(e));
      var shopId = e.currentTarget.dataset.id;
    console.log("shopId---"+shopId);
    wx.navigateTo({
      url: "./details/details?shopId="+shopId,
    })
  },

    //搜索店铺
    toSearch: function() {
        this.setData({
            curPage: 1,
            loadingMoreHidden: false
        });
        this.getShopList();
    },
    inputTyping: function(e) {
        this.setData({
            inputVal: e.detail.value
        });
    },
    // 以下为搜索框事件
    showInput: function() {
        this.setData({
            inputShowed: true
        });
    },
    clearInput: function() {
        this.setData({
            inputVal: ""
        });
    },
    getShopList: function() {
        let that=this;
        console.log("name="+that.data.inputVal);
        wx.showLoading({
            mask: true,
            title:'数据加载中...',
        });
        var params = {
            name: that.data.inputVal,
            pageSize: this.data.pageSize
        }
        wx.request({
            // url: con.index_forhome,
            url:'https://www.brvpmusic.com/api/community/likeBarberShopList',
            method: 'GET',
            data: params,
            header: {
                'Content-Type': 'application/json'
            },
            success: function (res) {
                wx.hideLoading();
                console.log(res.data);
                console.log('返回成功');
                var barbershop=res.data.body;
                that.setData({
                    barbershop:barbershop,
                })
            },
            fail: function (res) {
                console.log('返回失败');
            }
        })
    },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
    let that=this;
      wx.showLoading({
          mask: true,
          title:'数据加载中...',
      });
    wx.request({
      // url: con.index_forhome,
      //   url:'http://3s.dkys.org:12457/api/community/getBarberShopAll',
        url:'https://www.brvpmusic.com/api/community/getBarberShopAll',
      method: 'GET',
      header: {
        'Content-Type': 'application/json'
      },
      success: function (res) {
        console.log(res.data);
        console.log('返回成功');
        var barbershop=res.data.body;
        that.setData({
            barbershop:barbershop,
        });
        wx.hideLoading();
      },
      fail: function (res) {
        console.log('返回失败');
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})